package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.mapper.NursingProjectPlanMapper;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectPlanVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class NursingPlanServiceImpl implements NursingPlanService {
    private final NursingPlanMapper nursingPlanMapper;
    @Override
    public List<NursingPlanVo> findAll() {
        List<NursingPlan> nursingPlan = nursingPlanMapper.listAll();
        return BeanUtil.copyToList(nursingPlan, NursingPlanVo.class);
    }

    @Override
    public void addNursingPlan(NursingPlanDto nursingPlanDto) {
        NursingPlan nursingPlan = BeanUtil.copyProperties(nursingPlanDto, NursingPlan.class);
        nursingPlanMapper.insert(nursingPlan);

    }

    @Override
    public PageResponse<NursingPlanVo> selectPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //创建分页插件
        PageHelper.startPage(pageNum, pageSize);
        Page<List<NursingPlan>> nursingPlan =nursingPlanMapper.listByPage(pageSize, pageNum, name, status);
        return PageResponse.of(nursingPlan, NursingPlanVo.class);
    }

    @Override
    public NursingPlanVo selectById(Long id) {
        NursingPlan nursingPlan = nursingPlanMapper.getById(id);
        return BeanUtil.copyProperties(nursingPlan, NursingPlanVo.class);
    }

    @Override
    public void updateNursingPlan(NursingPlanDto nursingPlanDto) {
        NursingPlan nursingPlan = BeanUtil.copyProperties(nursingPlanDto, NursingPlan.class);
        nursingPlanMapper.update(nursingPlan);


    }

    @Override
    public void deleteById(Long id) {
        nursingPlanMapper.deleteById(id);

    }

    @Override
    public void startOrStop(Long id, Integer status) {
        nursingPlanMapper.updateStatus(id,status);
    }
}
